package cc.rengu.igas.cops.core.service.trans.unionpay;

import cc.rengu.igas.channel.upqc.facade.bean.PayeeInfoBean;
import cc.rengu.igas.channel.upqc.facade.request.B2CQueryOrderRequest;
import cc.rengu.igas.channel.upqc.facade.response.B2CQueryOrderResponse;
import cc.rengu.igas.channel.upqc.facade.result.Result;
import cc.rengu.igas.cops.common.constant.CopsParamConstant;
import cc.rengu.igas.cops.common.enums.QrBindStatusEnum;
import cc.rengu.igas.cops.common.enums.RespCodeEnum;
import cc.rengu.igas.cops.common.util.QrCodeUtil;
import cc.rengu.igas.cops.facade.bean.PayeeInfo;
import cc.rengu.igas.cops.facade.request.BankB2cQueryOrderRequest;
import cc.rengu.igas.cops.facade.response.BankB2cQueryOrderResponse;
import cc.rengu.igas.share.core.model.QrCodeInfo;
import cc.rengu.igas.share.core.realize.BompService;
import cc.rengu.igas.share.core.realize.impl.BompServiceImpl;
import cc.rengu.oltp.service.base.BizBaseService;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.dao.UserOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.impl.UserOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.entity.ChannelCallCfg;
import cc.rengu.oltp.service.common.entity.SysParam;
import cc.rengu.oltp.service.common.entity.UserOrderInfo;
import cc.rengu.oltp.service.common.enums.*;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.model.OrderInfo;
import cc.rengu.oltp.service.model.RiskMonitorInfo;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.OrderService;
import cc.rengu.oltp.service.realize.SysParamService;
import cc.rengu.oltp.service.realize.TransCustomImpl;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;
import cc.rengu.oltp.service.realize.impl.OrderServiceImpl;
import cc.rengu.oltp.service.realize.impl.SysParamServiceImpl;
import cc.rengu.oltp.utility.util.*;
import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 主扫---订单查询
 * 手机【ESB】—>支付—>通道—>银联
 * <p>
 * 订单表字段：
 * remark1：二维码类型
 * remark2：收款方信息JSON
 * remark3：优惠信息json list
 * front_seq_num前端流水号：付款凭证号
 *
 * @author panky
 * @version 1.0.0 创建时间：2020.06.23
 */
public class BankB2cQueryOrderService extends BizBaseService implements TransCustomImpl {

    @Override
    protected Object beforeBizProcess() throws Exception {
        BankB2cQueryOrderRequest bankB2cQueryOrderRequest = new BankB2cQueryOrderRequest();
        ConvertUtil.convertOutput(bankB2cQueryOrderRequest);
        return bankB2cQueryOrderRequest;
    }

    @Override
    protected BizResponse callBizService(Object request) throws Exception {
        // 录入参数
        BankB2cQueryOrderRequest bankB2cQueryOrderRequest = (BankB2cQueryOrderRequest) request;
        // 行号
        String instId = bankB2cQueryOrderRequest.getHeader().getInstId();

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        // 没有上传二维码编号
        if (StringUtil.isEmptyOrNull(bankB2cQueryOrderRequest.getQrNo())) {
            rglog.error("银联二维码<{}>不能为空!", instId, bankB2cQueryOrderRequest.getQrNo());
            throw new BizException(RespCodeEnum.GET_QRCODE_INFO_ERROR.getRespCode(), RespCodeEnum.GET_QRCODE_INFO_ERROR.getRespDesc());
        }

        // 他行码暂时只支持银标码
        if (!bankB2cQueryOrderRequest.getQrNo().startsWith("https://qr.95516.com/")) {
            rglog.error("不支持的二维码：<{}>!", instId, bankB2cQueryOrderRequest.getQrNo());
            throw new BizException(RespCodeEnum.QRCODE_TRANS_FILED.getRespCode(), RespCodeEnum.QRCODE_TRANS_FILED.getRespDesc());
        }

        //去掉C1码中的tt和si参数
        String qrCodeUrl = bankB2cQueryOrderRequest.getQrNo();

        //本行码
        if (isOwnQrCode(qrCodeUrl)
                && qrCodeUrl.indexOf("inf=U") == -1) {

            //本行码过滤掉si和tt
            qrCodeUrl = QrCodeUtil.filterTtAndSi(bankB2cQueryOrderRequest.getQrNo());
            BompService bompService = new BompServiceImpl();
            QrCodeInfo qrCodeInfo = bompService.getQrCodeInfo(instId, qrCodeUrl, null);
            if (qrCodeInfo != null) {
                String currentTime = DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS");
                if (!qrCodeInfo.getQrStatus().equals("00")) {
                    rglog.info("当前二维码未绑定商户，不可用.qrCodeBindStatus:<{}>", qrCodeInfo.getBindStatus());
                    throw new BizException(RespCodeEnum.GET_QRCODE_INVALID.getRespCode(), RespCodeEnum.GET_QRCODE_INVALID.getRespDesc());
                } else if (QrBindStatusEnum.UNBIND.getBindStatus().equals(qrCodeInfo.getBindStatus())) {
                    rglog.info("当前二维码未绑定商户，不可用.qrCodeBindStatus:<{}>", qrCodeInfo.getBindStatus());
                    throw new BizException(RespCodeEnum.GET_QRCODE_INVALID.getRespCode(), RespCodeEnum.GET_QRCODE_INVALID.getRespDesc());
                } else if (!StringUtil.isEmptyOrNull(qrCodeInfo.getEffectiveTime())
                        && DateUtil.compareTime(currentTime, qrCodeInfo.getEffectiveTime(), "yyyy-MM-dd HH:mm:ss.SSS") < 0) {
                    rglog.error("二维码未生效!");
                    throw new BizException(RespCodeEnum.GET_QRCODE_INVALID.getRespCode(), RespCodeEnum.GET_QRCODE_INVALID.getRespDesc());
                } else if (!StringUtil.isEmptyOrNull(qrCodeInfo.getExpiryTime())
                        && DateUtil.compareTime(currentTime, qrCodeInfo.getExpiryTime(), "yyyy-MM-dd HH:mm:ss.SSS") > 0) {
                    rglog.error("二维码已失效!");
                    throw new BizException(RespCodeEnum.GET_QRCODE_INVALID.getRespCode(), RespCodeEnum.GET_QRCODE_INVALID.getRespDesc());
                }

                //本行静态码
                return qrCodeResponseConvert(bankB2cQueryOrderRequest, qrCodeInfo);
            }

            UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
            UserOrderInfo userOrderInfo = userOrderInfoMapper.selectUserOrderInfoByOrderUrl(instId, qrCodeUrl);
            if (userOrderInfo != null) {
                //本行动态码
                return userOrderInfoResponseConvert(bankB2cQueryOrderRequest, userOrderInfo);
            }
        }

        //手机银行和直销银行可能不适用同一个银联机构号，通过渠道id区分
        String channelId = bankB2cQueryOrderRequest.getHeader().getChanlId();

        //银联他行码
        SysParamService sysParamService = new SysParamServiceImpl();

        /* 银联码，获取法人行在银联的机构号 */
        SysParam unionPayCode = sysParamService.getSysParamInfo(instId, "OPMS_SYS_PARAM", "unionPayerOrgCode" + "_" + channelId);
        if (null == unionPayCode) {
            rglog.error("获取二维码服务失败！获取付款方法人行在银联的机构号失败！instId:{}", instId);
            throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
        }

        // 银联机构号
        String strUnonPayCode = unionPayCode.getParamValue();

        // 请求银联
        B2CQueryOrderRequest b2CQueryOrderRequest = new B2CQueryOrderRequest();
        // 银联机构号
        b2CQueryOrderRequest.setIssInsCode(strUnonPayCode);
        // 二维码
        b2CQueryOrderRequest.setQrCode(qrCodeUrl);
        cc.rengu.igas.channel.upqc.facade.base.Header upHeader = new cc.rengu.igas.channel.upqc.facade.base.Header();
        BeanUtil.beanCopy(bankB2cQueryOrderRequest.getHeader(), upHeader);
        upHeader.setTxnNum("0120000903");// 查询订单
        upHeader.setSrcSysId("OPMS");
        b2CQueryOrderRequest.setHeader(upHeader);
        DubboService dubboService = new DubboServiceImpl();
        Result<B2CQueryOrderResponse> responseResult = (Result<B2CQueryOrderResponse>) dubboService.callDubboService("upqcPayerService", "b2cQueryOrder", b2CQueryOrderRequest);
        if (null == responseResult || !responseResult.isSuccess() || !"00000000".equals(responseResult.getResult().getRespCode())) {
            rglog.error("调用银联查询二维码信息失败，二维码<{}>信息失败,iReturnCode:<{}>", qrCodeUrl,
                    responseResult.getResult().getRespCode());
            throw new BizException(responseResult.getResult().getRespCode(),
                    responseResult.getResult().getRespDesc());
        }
        BankB2cQueryOrderResponse bankB2cQueryOrderResponse = new BankB2cQueryOrderResponse();
        // 生成订单
        UserOrderInfo orderInfo = initOrderInfoUser(bankB2cQueryOrderRequest, responseResult.getResult(), bankB2cQueryOrderResponse);

        OrderService orderService = new OrderServiceImpl();
        /*注册登记订单*/
        if (!orderService.registerOrderInfo(orderInfo, null, null)) {
            rglog.error("订单创建失败");
            throw new BizException(RespCodeEnum.INSERT_PAY_ORDER_ERROR.getRespCode(), RespCodeEnum.INSERT_PAY_ORDER_ERROR.getRespDesc());
        }
        // 交易序列号	txnNo
        bankB2cQueryOrderResponse.setTxnNo(orderInfo.getSysSeqNum());
        //订单类型	orderType
        bankB2cQueryOrderResponse.setOrderType(orderInfo.getOrderType());
        //支付有效时间	paymentValidTime
        // 支付有效时间 单位秒
        String qrValidTime = responseResult.getResult().getPaymentValidTime();
        if (cc.rengu.utility.base.StringUtil.isNullorEmpty(qrValidTime)) {
            // 默认是3分钟
            qrValidTime = "180";
        }
        bankB2cQueryOrderResponse.setPaymentValidTime(qrValidTime);
        PayeeInfo opmsPayeeInf = new PayeeInfo();
        BeanUtil.beanCopy(responseResult.getResult().getPayeeInfoBean(), opmsPayeeInf);
        //返回给手机银行的ATM取款金额单位为元
        if (opmsPayeeInf != null && !StringUtil.isEmptyOrNull(opmsPayeeInf.getAmount())) {
            opmsPayeeInf.setAmount(AmountUtil.changeF2Y(opmsPayeeInf.getAmount()));
        }
        //收款方信息	payeeInfo ---收款商户名
        bankB2cQueryOrderResponse.setPayeeInfo(opmsPayeeInf);
        //订单金额	txnAmt
        bankB2cQueryOrderResponse.setTxnAmt(responseResult.getResult().getOrderAmt());
        //订单号	unid
        bankB2cQueryOrderResponse.setUnid(orderInfo.getSysSeqNum());
        //ATM的codeType不赋值
        if (!"20".equals(responseResult.getResult().getOrderType())) {
            //固定值，用以与老平台区分
            bankB2cQueryOrderResponse.setCodeType("1");
        }
        //他行码
        bankB2cQueryOrderResponse.setQrCodeUrl(createOtherQrCodeUrl(instId, bankB2cQueryOrderRequest.getQrNo(), orderInfo.getSysSeqNum()));

        /** 861、867行的主扫页面标题显示为云闪付 */
        if (instId.equals("861")
                || instId.equals("867")) {
            bankB2cQueryOrderResponse.setTitle("云闪付");
        } else {
            bankB2cQueryOrderResponse.setTitle("扫一扫");
        }
        //平台日期
        bankB2cQueryOrderResponse.setPtrq(DateUtil.getCurrentDate());
        //平台流水号
        bankB2cQueryOrderResponse.setPtlsh(xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM));
        // 返回
        BizResponse bizResponse = new BizResponse();
        bizResponse.setResult(bankB2cQueryOrderResponse);// 返回结果
        bizResponse.setRspSysId(AppParamConstant.IGAS);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        return bizResponse;
    }

    /**
     * 登记用户订单表
     *
     * @throws Exception 异常
     */
    private UserOrderInfo initOrderInfoUser(BankB2cQueryOrderRequest bankB2cQueryOrderRequest,
                                            B2CQueryOrderResponse b2CQueryOrderResponse,
                                            BankB2cQueryOrderResponse bankB2cQueryOrderResponse) throws Exception {

        UserOrderInfo userOrderInfo = new UserOrderInfo();
        userOrderInfo.setInstId(bankB2cQueryOrderRequest.getHeader().getInstId());// 机构标识
        userOrderInfo.setTxnDate(DateUtil.getCurrentDate());// 交易日期
        userOrderInfo.setTxnTime(DateUtil.getCurrentTime());// 交易时间
        userOrderInfo.setTxnNum(bankB2cQueryOrderRequest.getHeader().getTxnNum());// 内部交易码
        userOrderInfo.setBizType(bankB2cQueryOrderRequest.getHeader().getBizType());// 业务细分
        userOrderInfo.setMsgSrcId(ChannelEnum.COPS.getChannelType());// 源系统标识
        userOrderInfo.setTransChannelId("MOBILE");
        // 商户订单号不存子啊，使用系统流水号
        userOrderInfo.setMchntOrderId(bankB2cQueryOrderRequest.getHeader().getTraceNo());
        // 订单创建时间
        userOrderInfo.setOrderCreateTime(DateUtil.getCurrentDateTime("yyyyMMddHHmmss"));
        // 支付有效时间 单位秒
        String qrValidTime = b2CQueryOrderResponse.getPaymentValidTime();
        if (cc.rengu.utility.base.StringUtil.isNullorEmpty(qrValidTime)) {
            // 默认是3分钟
            qrValidTime = "180";
        }
        int iQrValidTime = Integer.parseInt(qrValidTime);
        // 交易序列号
        userOrderInfo.setSysSeqNum(b2CQueryOrderResponse.getTxnNo());
        userOrderInfo.setOrderUrl(b2CQueryOrderResponse.getTxnNo());
        // 订单有效时间
        userOrderInfo.setOrderExpiryTime(DateUtil.getDateByTimeStamp(System.currentTimeMillis() + iQrValidTime * 1000, "yyyyMMddHHmmss"));
        userOrderInfo.setOrderStatus(OrderStatusEnum.INIT.getStatus());
        userOrderInfo.setTransStatus(TransStatusEnum.TRANS_INIT.getStatus());
        // 01-业务处理中 40-授权未完成【待密码认证】
        userOrderInfo.setBizStatus(BizStatusEnum.INIT.getStatus());
        // 收款方信息
        PayeeInfoBean payeeInf = b2CQueryOrderResponse.getPayeeInfoBean();
        // 平台商户/集团商户/代理商商户号
        userOrderInfo.setGroupMchntNo(payeeInf.getId());
        // 平台商户/集团商户/代理商商户名称
        userOrderInfo.setGroupMchntName(payeeInf.getName());
        // 订单金额
        userOrderInfo.setOrderAmt(b2CQueryOrderResponse.getOrderAmt());
        // 订单币种
        userOrderInfo.setOrderCcy(b2CQueryOrderResponse.getOrderCcy());
        //将二维码类型存放在拓展字段
        Map<String, String> orderExtraInfo = new HashMap<String, String>();
        if (StringUtil.isEmptyOrNull(b2CQueryOrderResponse.getQrCodeType())
                || b2CQueryOrderResponse.getQrCodeType().equals("1")) {
            // 静态码  银联返回的静态码值为1，数据库静态码值为0
            orderExtraInfo.put("qrCodeType", "0");
        } else {
            // 动态码
            orderExtraInfo.put("qrCodeType", "1");
        }
        userOrderInfo.setOrderExtraInfo(JSON.toJSONString(orderExtraInfo));
        //收款方附言	payeeComments
        bankB2cQueryOrderResponse.setPayeeComments(b2CQueryOrderResponse.getPayeeComments());
        //二维码类型
        bankB2cQueryOrderResponse.setQrCodeType(orderExtraInfo.get("qrCodeType"));
        // 订单类型
        // 10:一般消费 11:限定非贷记帐户支付的消费，例如购买理财产品 12:小微商户收款 20：ATM 31:人到人转账(不能使用贷记卡支付) 40：预授权交易
        userOrderInfo.setOrderType(b2CQueryOrderResponse.getOrderType());
        // 创建时间
        userOrderInfo.setCreateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        // 收款人信息JSON
        userOrderInfo.setRemark2(JSON.toJSONString(b2CQueryOrderResponse.getPayeeInfoBean()));

        return userOrderInfo;
    }

    @Override
    protected void afterBizProcess(BizResponse response) throws Exception {
        BankB2cQueryOrderResponse retResponse = (BankB2cQueryOrderResponse) response.getResult();
        ConvertUtil.convertInput(retResponse);
    }

    @Override
    protected RiskMonitorInfo getRiskMonitorInfo() {
        return null;
    }


    /**
     * 银联本行码按照本行码方式返回支付页面路径
     *
     * @param request
     * @return
     * @throws Exception
     */
    private BizResponse qrCodeResponseConvert(BankB2cQueryOrderRequest request, QrCodeInfo qrCodeInfo) throws Exception {
        String instId = request.getHeader().getInstId();

        BankB2cQueryOrderResponse bankB2cQueryOrderResponse = new BankB2cQueryOrderResponse();
        bankB2cQueryOrderResponse.setPaymentValidTime("180");
        PayeeInfo opmsPayeeInf = new PayeeInfo();

        //收款方信息	payeeInfo ---收款商户名
        bankB2cQueryOrderResponse.setPayeeInfo(opmsPayeeInf);
        //银联交易码
        bankB2cQueryOrderResponse.setTxnNo(request.getHeader().getTraceNo());
        //订单金额	txnAmt
        bankB2cQueryOrderResponse.setTxnAmt("");
        //订单号	unid
        bankB2cQueryOrderResponse.setUnid(request.getHeader().getTraceNo());
        // 二维码类型 0：动态码 1：静态码
        bankB2cQueryOrderResponse.setQrCodeType("1");
        //固定值，用以与老平台区分
        bankB2cQueryOrderResponse.setCodeType("1");

        if (qrCodeInfo != null && qrCodeInfo.getQrStatus().equals("00")) {
            //本行码
            bankB2cQueryOrderResponse.setQrCodeUrl(createSelfQrCodeUrl(instId, request.getQrNo()));
        }

        bankB2cQueryOrderResponse.setTitle("扫一扫");
        // 返回
        BizResponse bizResponse = new BizResponse();
        bizResponse.setResult(bankB2cQueryOrderResponse);// 返回结果
        bizResponse.setRspSysId(AppParamConstant.IGAS);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        return bizResponse;
    }

    /**
     * 银联本行码按照本行码方式返回支付页面路径
     *
     * @param request
     * @return
     * @throws Exception
     */
    private BizResponse userOrderInfoResponseConvert(BankB2cQueryOrderRequest request, UserOrderInfo userOrderInfo) throws Exception {
        String instId = request.getHeader().getInstId();

        BankB2cQueryOrderResponse bankB2cQueryOrderResponse = new BankB2cQueryOrderResponse();
        bankB2cQueryOrderResponse.setPaymentValidTime("180");
        PayeeInfo opmsPayeeInf = new PayeeInfo();

        //收款方信息	payeeInfo ---收款商户名
        bankB2cQueryOrderResponse.setPayeeInfo(opmsPayeeInf);
        //银联交易码
        bankB2cQueryOrderResponse.setTxnNo(request.getHeader().getTraceNo());
        //订单金额	txnAmt
        bankB2cQueryOrderResponse.setTxnAmt("");
        //订单号	unid
        bankB2cQueryOrderResponse.setUnid(request.getHeader().getTraceNo());
        // 二维码类型 0：动态码 1：静态码
        bankB2cQueryOrderResponse.setQrCodeType("0");
        //固定值，用以与老平台区分
        bankB2cQueryOrderResponse.setCodeType("1");

        if (userOrderInfo != null) {
            //本行码
            bankB2cQueryOrderResponse.setQrCodeUrl(createSelfQrCodeUrl(instId, request.getQrNo()));
        }

        bankB2cQueryOrderResponse.setTitle("扫一扫");
        // 返回
        BizResponse bizResponse = new BizResponse();
        bizResponse.setResult(bankB2cQueryOrderResponse);// 返回结果
        bizResponse.setRspSysId(AppParamConstant.IGAS);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        return bizResponse;
    }


    /**
     * 拼接银联他行码跳转地址
     *
     * @param instId
     * @param codeUrl
     * @param txnNo
     * @return
     * @throws Exception
     */
    private String createOtherQrCodeUrl(String instId, String codeUrl, String txnNo) throws Exception {
        SysParamService paramService = new SysParamServiceImpl();
        SysParam sysParam = paramService.getSysParamInfo(instId, "OPMS_SYS_PARAM", "T00CO021QR");

        StringBuilder sbd = new StringBuilder();
        sbd.append(sysParam.getParamValue());
        if (sysParam.getParamValue().indexOf("?") == -1) {
            sbd.append("?");
        }
        sbd.append("codeFlag1=2&codeId=");
        sbd.append(txnNo);
        sbd.append("&inf=");
        String[] parMap = codeUrl.split("\\/");
        if (parMap[4].indexOf("inf=") > -1) {
            sbd.append(parMap[4].substring(parMap[4].indexOf("inf=") + 4));
        } else {
            sbd.append(parMap[4]);
        }
        sbd.append("&payCodeInfo=");
        sbd.append(StringUtil.binaryToBase64String(codeUrl.getBytes("UTF-8")));
        return sbd.toString();
    }

    /**
     * 拼接银联本行码跳转地址
     *
     * @param instId
     * @param codeUrl
     * @return
     * @throws Exception
     */
    private String createSelfQrCodeUrl(String instId, String codeUrl) throws Exception {
        SysParamService paramService = new SysParamServiceImpl();
        SysParam sysParam = paramService.getSysParamInfo(instId, "OPMS_SYS_PARAM", "T00CO021QR");

        StringBuilder sbd = new StringBuilder();
        sbd.append(sysParam.getParamValue());
        if (sysParam.getParamValue().indexOf("?") == -1) {
            sbd.append("?");
        }
        sbd.append("inf=");
        String[] parMap = codeUrl.split("\\/");
        if (parMap[4].indexOf("inf=") > -1) {
            sbd.append(parMap[4].substring(parMap[4].indexOf("inf=") + 4));
        } else {
            sbd.append(parMap[4]);
        }
        sbd.append("&payCodeInfo=");
        sbd.append(StringUtil.binaryToBase64String(codeUrl.getBytes("UTF-8")));
        return sbd.toString();
    }


    /**
     * 判断二维码是否是本行码
     *
     * @param qrUrl
     * @return
     */
    boolean isOwnQrCode(String qrUrl) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String instId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.INST_ID);

        //银联他行码
        SysParamService sysParamService = new SysParamServiceImpl();
        /* 银联码，获取法人行在银联的机构号 */
        SysParam bankUnionPayCode = sysParamService.getSysParamInfo(instId, CopsParamConstant.MCHNT_PARAM_TYPE, CopsParamConstant.CUPS_INSR_ID);
        if (null == bankUnionPayCode) {
            rglog.error("获取法人行在银联的机构号失败！instId:{}", instId);
            throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
        }

        if (!StringUtil.isEmptyOrNull(qrUrl)) {
            String[] values = qrUrl.split("\\/");
            if (bankUnionPayCode.getParamValue().equals(values[3])) {
                return true;
            }
        }
        return false;
    }

    @Override
    public ChannelCallCfg channelCallSceneDiscern(Object request, List<ChannelCallCfg> channelCallCfgList) throws Exception {
        return null;
    }

    @Override
    public CheckResultEnum channelCallPreCheck(Object request, ChannelCallCfg channelCallCfg, OrderInfo orderInfo) throws Exception {
        return null;
    }

    @Override
    public TransStatusEnum channelCallResultProc(Object request, ChannelCallCfg channelCallCfg, TransStatusEnum transStatusEnum, Object channelResponse, OrderInfo needUpdateOrderInfo) throws Exception {
        return null;
    }
}
